<script setup>
import {ref} from "vue";

const arr = ref([
  {title:'apple',price:20,num:100},
  {title:'orange',price:30,num:200},
  {title:'pile',price:10,num:300},
  {title:'watermelon',price:70,num:900}
])

const del = (b)=>{
  if(confirm('are you sure delete the fruit?')){
    arr.value.splice(b,1)
  }
}
</script>

<template>
<h1>循环指令</h1>
  <ul style="list-style: none">
    <li v-for="item in 5">{{item}}</li>
  </ul>
  <ul style="list-style: none">
    <li v-for="a in arr">{{a}}</li>
  </ul>
  <table border="2px">
    <tr>
      <th>id</th>
      <th>title</th>
      <th>price</th>
      <th>num</th>
      <th>operator</th>
    </tr>
    <tr v-for="(a,b) in arr">
      <td>{{b+1}}</td>
      <td>{{a.title}}</td>
      <td>{{a.price}}</td>
      <td>{{a.num}}</td>
      <td><button @click="del(b)">删除</button></td>
    </tr>
  </table>
</template>

<style scoped>

</style>